﻿app.controller('polygonController', function PostsController($scope, $filter, PolygonFactory) {
   
    $scope.loading = true;
    $scope.addMode = false;
    $scope.success = false;
   
  /*  $scope.isInvalid = function (field) {
        return $scope.form[field].$invalid && $scope.form[field].$dirty;
    };
    $scope.isValid = function (field) {
        return $scope.form[field].$valid && $scope.form[field].$dirty;
    };*/
  
    $scope.waitMessage = "טוען נא להמתין";

    $scope.closeDialog = function () {
        $scope.message = null;
    };

   

    $scope.save = function () {
        $scope.waitMessage = "שומר ";
       // var Polyg = this.Polygon;
        PolygonFactory.updatePolygon($scope.Polygon).success(function (response) {
           
            if (response) {
              
                
                    $scope.message = response;
                    $scope.success = true;
                    $scope.Polygon = angular.copy($scope.Polygon);
                  
                    
                   
            }
            $scope.waitMessage = null;
        });
    };

    $scope.clear = function () {
        $scope.message = null;
        $scope.success = false;

    };
   


    //get all Customers
    PolygonFactory.getPolygon(getParameterByName("ID")).success(function (data) {
       
        $scope.Polygon = data;
        $scope.Polygon.StartDate = $filter('date')($scope.Polygon.StartDate, "dd/MM/yyyy");
        $scope.loading = false;
        $scope.waitMessage = null;
       
    })
.error(function (data) {
    $scope.error = "An Error has occured while loading posts! " + data.ExceptionMessage;
    $scope.loading = false;
});

});